package l1j.server.server.clientpackets;

import static l1j.server.server.model.skill.L1SkillId.TELEPORT_DELAY;
import l1j.server.echo.ClientThread;
import l1j.server.server.model.Instance.L1PcInstance;
import l1j.server.server.utils.Teleportation;

import java.util.logging.Level;
import java.util.logging.Logger;
// Referenced classes of package l1j.server.server.clientpackets:
// ClientBasePacket

/**
 * 處理收到由客戶端傳來傳送的封包
 */
public class C_Teleport extends ClientBasePacket {

	private static final String C_TELEPORT = "[C] C_Teleport";
	private static final Logger _log = Logger.getLogger(C_Teleport.class.getName());
	@Override
	public String getType() {
		return C_TELEPORT;
	}

	@Override
	public void start(final byte[] decrypt, final ClientThread client) {
		try {
			// 資料載入
			this.read(decrypt);
			final L1PcInstance pc = client.getActiveChar();
			if (pc == null) {
				return;
			}
			if(pc.isDead() || pc.isInHell()){
				pc.killSkillEffectTimer(TELEPORT_DELAY);
				return;
			}
			if(pc.isCantTeleport()){
				pc.killSkillEffectTimer(TELEPORT_DELAY);
				return;
			}
			
			Teleportation.actionTeleportation(pc);
		} catch (final Exception e) {
			_log.log(Level.SEVERE, e.getLocalizedMessage(), e);
		} finally {
			this.over();
		}
	}
}
